package com.user.service.impl;

import com.user.dao.TokenDao;
import com.user.pojo.Token;
import com.user.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class TokenServiceImpl implements TokenService {

    @Autowired
    private TokenDao lagouTokenDao;

    @Override
    public String createToken() {
        return UUID.randomUUID().toString();
    }

    @Override
    public void saveToken(String email, String token) {
        Token token1 = new Token();
        token1.setEmail(email);
        token1.setToken(token);
        lagouTokenDao.save(token1);
    }

    @Override
    public String getEmail(String token) {
        return lagouTokenDao.findByToken(token).getEmail();
    }
}
